package com.kanshu.mvp_basic.demo_user_info.presenter;

import android.text.TextUtils;

import com.kanshu.mvp_basic.demo_user_info.bean.UserBean;
import com.kanshu.mvp_basic.demo_user_info.model.IUserModel;
import com.kanshu.mvp_basic.demo_user_info.model.UserModelImpl;
import com.kanshu.mvp_basic.demo_user_info.view.IUserView;

public class UserPresenterImpl implements IUserPresenter {

    private static final String TAG = "UserPresenterImpl";

    private IUserView mUserView;
    private IUserModel mUserModel;

    public UserPresenterImpl(IUserView mUserView) {
        this.mUserView = mUserView;
        this.mUserModel = new UserModelImpl();
    }

    @Override
    public void saveUser() {

        if (TextUtils.isEmpty(mUserView.getUserName()) || TextUtils.isEmpty(mUserView.getUserPassword())) {
            mUserView.showToast("保存失败，用户名或密码为空！");
        } else {
            mUserModel.saveUser(mUserView.getID(), mUserView.getUserName(), mUserView.getUserPassword());
            mUserView.showToast("保存成功！");
        }

    }

    @Override
    public void loadUser() {
        UserBean userBean = mUserModel.loadUser(mUserView.getID());
        if (userBean != null) {
            mUserView.setUserName(userBean.getName());
            mUserView.setUserPassword(userBean.getPassword());
        }

    }
}
